package com.masterclient.app.businessmodule.minemodule.message.detail

import android.os.Bundle
import android.support.design.widget.TabLayout
import android.support.v4.app.Fragment
import android.view.View
import com.eoner.managerlibrary.user.UserDataManager
import com.eoner.baselib.widget.navgation.FCNavigationBar
import com.eoner.baselibrary.bean.personal.GivingListBean
import com.masterclient.app.R
import com.masterclient.app.base.FCBusinessActivity
import com.masterclient.app.businessmodule.minemodule.contract.ActivityListContract
import com.masterclient.app.businessmodule.minemodule.contract.ActivityListPresenter
import com.eoner.uikit.adapter.simplepage.CollectionPagerAdapter
import kotlinx.android.synthetic.main.activity_activity_msgs.*

/**
 * 作者：sean
 * 创建时间：2018/5/22 17:37
 * 功能说明：
 */
class ActivityListActivity:FCBusinessActivity<ActivityListPresenter>(),ActivityListContract.View{


    var list = ArrayList<Fragment>()
    var sTitle =ArrayList<Map<String,String>>()

    override fun requireGetLayoutId(): Int {
        return R.layout.activity_activity_msgs
    }

    override fun requireSetCustomNavigationBar(navigationBar: FCNavigationBar?) {
       navigationBar?.setTitle("向日葵活动");
    }

    override fun requireInitUIAndData(savedInstanceState: Bundle?) {

        mPresenter.getZsqNoticeList()
    }

    fun render() {
        var i = 0
        for (temp in sTitle) {

            var type = temp.get("type")
            if (type == "0") {
                tabLayout.addTab(temp.get("title"),true);
            } else {
                tabLayout.addTab(temp.get("title"),false);
            }

            if (type == "-1") {
                val fragment = GivingMsgFragment()
                list.add(fragment)
            } else {
//                val fragment = VipMsgFragment()
//                val bundle = Bundle()
//                bundle.putString("type",type)
//                fragment.arguments = bundle
//                list.add(fragment)
            }
            i++
        }

        val pagerAdapter = CollectionPagerAdapter(getSupportFragmentManager(),list)
        viewPager.setAdapter(pagerAdapter)
        viewPager.addOnPageChangeListener(TabLayout.TabLayoutOnPageChangeListener(tabLayout.getTabLayout()))
        tabLayout.setupWithViewPager(viewPager)
        if (sTitle.size > 2) {
            viewPager.setCurrentItem(1,false)
            viewPager.offscreenPageLimit = 2
        }

    }

    override fun showZsqFailed() {
        TODO("Not yet implemented")
    }

    override fun onClickPageStateErrorView() {
        super.onClickPageStateErrorView()
        mPresenter.getZsqNoticeList()
    }

    override fun showZsqListData(givingListBean: GivingListBean?) {
        if (givingListBean != null && givingListBean.data != null && givingListBean.data.list !=null && givingListBean.data.list.size > 0) {
            var map = HashMap<String,String>()
            map.put("type","-1")
            map.put("title","赠送权活动")
            sTitle.add(map)
        }
        var map = HashMap<String,String>()
        map.put("type","0")
        map.put("title","普通活动")
        sTitle.add(map)

        if (Integer.valueOf(UserDataManager.getInstance().roleLevel) > 0) {
            var map = HashMap<String,String>()
            map.put("type","1")
            map.put("title","会员活动")
            sTitle.add(map)
        }

        if (sTitle.size > 1) {
            tabLayout.visibility =  View.VISIBLE
        } else {
            tabLayout.visibility =  View.GONE
        }
        render()
    }

}